package com.baizhi.service;

import com.baizhi.dao.AdminMapper;
import com.baizhi.entity.Admin;
import com.baizhi.entity.AdminExample;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service("adminService")
@Transactional
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;
    AdminExample adminExample = new AdminExample();

    @Override

    public Admin login(String username, String password) {
        adminExample.createCriteria().andUsernameEqualTo(username);
        List<Admin> admin = adminMapper.selectByExample(adminExample);
        if(admin.size()==0){
            throw new RuntimeException("用户名错误！");
        }else{
            for (Admin admin1 : admin) {
                if(admin1.getPassword().equals(password)){
                    return admin1;
                }
            }
            throw new  RuntimeException("密码错误");
        }
    }
}
